package com.demo.compass.controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import log4j.controller.LoggerFiltroDTO;

import org.apache.log4j.Logger;
import org.compass.gps.impl.SingleCompassGps;
import org.springframework.beans.factory.annotation.Autowired;

import com.demo.persistencia.generica.dao.GenericDao;
import com.demo.persistencia.generica.dao.impl.CompassDaoImpl;
import com.demo.persistencia.generica.modelo.Log4jdata;
import com.demo.persistencia.generica.util.HibernateUtil;

@ManagedBean(name="motorBusquedaCompass")
@SessionScoped
public class MotorBusquedaCompass {
	
	private static Logger log = Logger.getLogger(MotorBusquedaCompass.class);
	private HibernateUtil hUtil;
	private List<Log4jdata> lstlog4jdata;
	private String sInput;
	
	@Autowired
    private SingleCompassGps compassGps;
    @Autowired
    private CompassDaoImpl<Log4jdata, Integer> compass;
	
	
	public MotorBusquedaCompass() {
		hUtil = new HibernateUtil();
		hUtil.IniciarContextoSpring();
		lstlog4jdata= new ArrayList<Log4jdata>();
		indexar();
	}
	
	public void busqueda(){
		log.info("En la busqueda");
		
	}
	 public void indexar() {
            System.out.println("En el indexar");
            compassGps = (SingleCompassGps)hUtil.getContextoSpring().getBean("compassGps");
            
	        compassGps.index();
	        compass=(CompassDaoImpl<Log4jdata, Integer>) hUtil.getContextoSpring().getBean("compassDao");
	        
	        lstlog4jdata = (ArrayList<Log4jdata>)compass.buscarPaginado("clase:*",10);

	        for (Log4jdata log4j : lstlog4jdata) {
	            System.out.println("Resultado : " + log4j.toString());
	        }
	    }
	 
	public List<Log4jdata> getLstlog4jdata() {
		return lstlog4jdata;
	}
	public void setLstlog4jdata(List<Log4jdata> lstlog4jdata) {
		this.lstlog4jdata = lstlog4jdata;
	}

	public String getsInput() {
		return sInput;
	}

	public void setsInput(String sInput) {
		this.sInput = sInput;
	}
	
	

}
